var addList = [];
var addTopicList = [];
var dataSource1 = new Array();
var dataSource2 = new Array();
//table的数据源
var table;   //table对象
var a = getQueryString('sendCouponId');
var user = 'qqq'
dataSource1 = [];
dataSource2 = [];
dataSource3 = [];

function show() {
    var bh = document.getElementsByClassName('bohui');
    bh[0].classList.remove('hidden');
}

function hide() {
    var bh = document.getElementsByClassName('bohui');
    bh[0].classList.add('hidden');
}
$.ajax({
    url: root.couponInter.coupon_queryAuditDetail,
    cache: false,  //禁用缓存
    type: "POST",
    dataType: 'json',
    // contentType: "application/json",
    data: {
        "sendCouponId": a
    },
    success: function (data) {
        console.log(data)
        var b = data.couponSend;
        sendCouponType = data.couponSend.sendCouponType;
        $('#sendCouponType').val(sendCouponType);
        $('#sendCouponCode').html(b.sendCouponCode);
        $('#sendCouponName').html(b.sendCouponName);
        $('#sendCouponDept').html(b.sendCouponDept);
        $('#sendCouponUser').html(b.sendCouponUser);
        $('#sendReasonDutyDept').html(sendDutyDept(b.sendReasonDutyDept));
        if (b.sendCouponReason == 11) {
            $('#sendCouponReason').html('质量问题');
        } else if (b.sendCouponReason == 12) {
            $('#sendCouponReason').html('无货问题');
        } else if (b.sendCouponReason == 21) {
            $('#sendCouponReason').html('配送延迟');
        } else if (b.sendCouponReason == 22) {
            $('#sendCouponReason').html('状态维护错误');
        } else if (b.sendCouponReason == 23) {
            $('#sendCouponReason').html('私自拒收');
        } else if (b.sendCouponReason == 24) {
            $('#sendCouponReason').html('包装/商品破损');
        } else if (b.sendCouponReason == 25) {
            $('#sendCouponReason').html('违规收费');
        } else if (b.sendCouponReason == 26) {
            $('#sendCouponReason').html('服务态度差');
        } else if (b.sendCouponReason == 27) {
            $('#sendCouponReason').html('错漏发');
        } else if (b.sendCouponReason == 31) {
            $('#sendCouponReason').html('退款时效慢');
        } else if (b.sendCouponReason == 32) {
            $('#sendCouponReason').html('发票信息有误');
        } else if (b.sendCouponReason == 33) {
            $('#sendCouponReason').html('退款金额有误');
        } else if (b.sendCouponReason == 34) {
            $('#sendCouponReason').html('开具发票时间延迟');
        } else if (b.sendCouponReason == 41) {
            $('#sendCouponReason').html('商品参数错误');
        } else if (b.sendCouponReason == 42) {
            $('#sendCouponReason').html('价格错误');
        } else if (b.sendCouponReason == 43) {
            $('#sendCouponReason').html('活动与实际不符');
        } else if (b.sendCouponReason == 44) {
            $('#sendCouponReason').html('活动优惠券补发');
        } else if (b.sendCouponReason == 45) {
            $('#sendCouponReason').html('活动优惠券发放');
        } else if (b.sendCouponReason == 51) {
            $('#sendCouponReason').html('特殊售后问题');
        } else if (b.sendCouponReason == 52) {
            $('#sendCouponReason').html('提升客户体验');
        } else if (b.sendCouponReason == 53) {
            $('#sendCouponReason').html('承诺错误');
        } else if (b.sendCouponReason == 54) {
            $('#sendCouponReason').html('售后时间长');
        } else if (b.sendCouponReason == 61) {
            $('#sendCouponReason').html('售后运费补偿');
        } else if (b.sendCouponReason == 62) {
            $('#sendCouponReason').html('错发运费补偿');
        } else if (b.sendCouponReason == 71) {
            $('#sendCouponReason').html('订单未流转');
        } else if (b.sendCouponReason == 72) {
            $('#sendCouponReason').html('活动未绑定优惠券、赠品');
        } else if (b.sendCouponReason == 73) {
            $('#sendCouponReason').html('系统自动取消');
        } else if (b.sendCouponReason == 74) {
            $('#sendCouponReason').html('页面缓存问题');
        }
        $('#description').html(b.description);
        // custlist(data);
        // document.getElementById('datatable1_filter').classList.add('f-l');
        // document.getElementById('datatable1_filter').classList.add('chaxun');
        // couponlist(data);
        if (data.couponSend.sendCustType == 11) {
            $("#custType").find("option:contains('签约客户(非分销)')").attr("selected", true);
        } else if (data.couponSend.sendCustType == 12) {
            $("#custType").find("option:contains('普通客户(分销)')").attr("selected", true);
        } else if (data.couponSend.sendCustType == 20) {
            $("#custType").find("option:contains('普通客户')").attr("selected", true);
        } else if (data.couponSend.sendCustType == 30) {
            $("#custType").find("option:contains('认证客户')").attr("selected", true);
        }
        console.log(data.couponSend.sendCouponType)
        if (data.couponSend.sendCouponType == 1) {

            $("#twoOrThree").css({
                display: "none"
            });
            $("#customer").css({
                display: "block"
            });
            $("#topic-1").css({
                display: "block"
            });
            $("#topic-2").css({
                display: "none"
            });
            $("#two").css({
                display: "none"
            });
            $("#two-1").css({
                display: "none"
            });
            $("#two-2").css({
                display: "none"
            });

            $("#two-3").css({
                display: "none"
            });
            $("#time").css({
                display: "none"
            });
            $("#securities").css({
                display: "block"
            });
            addList.push(data.couponSendCustomerList);
            addTopicList.push(data.couponSendTopicList);
            cust_list(addList);
            coupon_list(addTopicList);
            $("#pricetype").css({
                display: "none"
            });
            // coupon_list(data.couponSendTopicList);
        } else if (data.couponSend.sendCouponType == 2) {
            // if(data.couponSendCustomerList.length>0){
            //     $("#securities").css({
            //         display: "block"
            //     });
            // }else{
            //     $("#securities").css({
            //         display: "none"
            //     });
            // }
            $("#customerTypef1").css({
                display: "inline"
            });
            $("#customerTypef2").css({
                display: "inline"
            });
            $("#customerTypef0").css({
                display: "inline"
            });
            $("#twoOrThree").css({
                display: "block"
            });
            $("#two").css({
                display: "block"
            });
            $("#time").css({
                display: "block"
            });
            $("#topic-1").css({
                display: "none"
            });
            $("#topic-2").css({
                display: "block"
            });
            $('#sendCondition').val(data.couponSend.sendCondition);
            if (data.couponSend.sendCondition == 1) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            if (data.couponSend.sendCondition == 2) {
                $("#two").css({
                    display: "block"
                });
                $("#two-1").css({
                    display: "block"
                });
                $("#two-2").css({
                    display: "block"
                });
                $("#two-3").css({
                    display: "block"
                });
                $('#sendCondition').val(data.couponSend.sendCondition);
                $('#orderAmount').val(data.couponSend.orderAmount);
                var whosus= sessionStorage.getItem("whosus")
                if (data.couponSend.applWarehouse == whosus || data.couponSend.applWarehouse == whosus) {
                    document.getElementById("wareHouse").checked = true;
                    $("input[name='wareHouse']").each(function () {
                        $(this).prop("checked", true);
                    });
                } else {
                    var groupCheckbox = data.couponSend.applWarehouse.split(",");
                    for (var i = 0; i < groupCheckbox.length; i++) {
                        var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
                        var ss=""
                        $.each(warehouses.data,function(k,s){
                            if(groupCheckbox[i]==s.warehouseCode){
                                $('#wareHouse'+s.warehouseCode+'').prop("checked", true);
                            }
                        })
                        /*if (groupCheckbox[i] == '1') {
                            $('#wareHouse1').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '2') {
                            $('#wareHouse2').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '4') {
                            $('#wareHouse3').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '5') {
                            $('#wareHouse4').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '9') {
                            $('#wareHouse5').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '10') {
                            $('#wareHouse6').prop("checked", true);
                        }*/
                    }
                }
                var groupCheckbox = data.couponSend.applPaidType.split(",");
                for (var i = 0; i < groupCheckbox.length; i++) {
                    if (groupCheckbox[i] == '1001') {
                        $('#payType1').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1301') {
                        $('#payType2').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1401') {
                        $('#payType3').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1101') {
                        $('#payType4').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1201') {
                        $('#payType5').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1701') {
                        $('#payType6').prop("checked", true);
                    }
                }
            }
            if (data.couponSend.sendCondition == 3) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            if (data.couponSend.sendCondition == 4) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            if (data.couponSend.customerType == '40') {
                document.getElementById("customerType").checked = true;
                $("input[name='customerType']").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                var groupCheckbox = data.couponSend.customerType.split(",");
                for (var i = 0; i < groupCheckbox.length; i++) {
                    if (groupCheckbox[i] == '11') {
                        $('#customerType1').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '12') {
                        $('#customerType2').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '20') {
                        $('#customerType3').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '30') {
                        $('#customerType4').prop("checked", true);
                    }

                }
            }
            //全选按钮选中
            var groupCheckbox = $("input[name='customerType']");
            var groupCheckboxall=$("input[name='customerType']:checked")
            if(groupCheckboxall.length==groupCheckbox.length){
                document.getElementById("customerType").checked = true;

            }else {
                document.getElementById("customerType").checked = false;

            }
            $('#logmin').val(data.couponSend.startTime);
            if (b.endTime != null && b.endTime != '') {
                $('#logmax').val(b.endTime);
            } else {
                $('#logmax').css({
                    display: "none"
                });
                $("#word").css({
                    display: "block"
                });
            }
            addList.push(data.couponSendCustomerList);
            addTopicList.push(data.couponSendTopicList);
            cust_list(addList);
            coupon_list_2(addTopicList);
            if(data.couponSend.sendCondition==4){
                $("#pricetype").css({
                    display: "inline"
                });
                if(data.couponSend.priceType==20){
                    $('#priceType1').prop("checked", true);
                }else if(data.couponSend.priceType==10){
                    $('#priceType2').prop("checked", true);
                }else if(data.couponSend.priceType==0){
                    $('#priceType0').prop("checked", true);
                }
            }else {
                $("#pricetype").css({
                    display: "none"
                });
            }

        } else if (data.couponSend.sendCouponType == 3) {
            // if(data.couponSendCustomerList.length>0){
            //     $("#securities").css({
            //         display: "block"
            //     });
            // }else{
            //     $("#securities").css({
            //         display: "none"
            //     });
            // }
            $("#customerTypef1").css({
                display: "inline"
            });
            $("#customerTypef2").css({
                display: "inline"
            });
            $("#customerTypef0").css({
                display: "inline"
            });
            $("#twoOrThree").css({
                display: "block"
            });
            $("#two").css({
                display: "none"
            });
            $("#two-1").css({
                display: "none"
            });
            $("#two-2").css({
                display: "none"
            });

            $("#two-3").css({
                display: "none"
            });
            $("#topic").show();
            $("#topic-1").hide();
            $("#time").show();
            if (data.couponSend.customerType == '40') {
                document.getElementById("customerType").checked = true;
                $("input[name='customerType']").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                var groupCheckbox = data.couponSend.customerType.split(",");
                for (var i = 0; i < groupCheckbox.length; i++) {
                    if (groupCheckbox[i] == '11') {
                        $('#customerType1').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '12') {
                        $('#customerType2').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '20') {
                        $('#customerType3').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '30') {
                        $('#customerType4').prop("checked", true);
                    }
                }
            }
            //全选按钮选中
            var groupCheckbox = $("input[name='customerType']");
            var groupCheckboxall=$("input[name='customerType']:checked")
            if(groupCheckboxall.length==groupCheckbox.length){
                document.getElementById("customerType").checked = true;

            }else {
                document.getElementById("customerType").checked = false;

            }
            $('#logmin').val(data.couponSend.startTime);

            if (b.endTime != null && b.endTime != '') {
                $('#logmax').val(b.endTime);
            } else {
                $('#logmax').css({
                    display: "none"
                });
                $("#word").css({
                    display: "block"
                });
            }
            addList.push(data.couponSendCustomerList);
            addTopicList.push(data.couponSendTopicList);
            cust_list(addList);
            coupon_list_2(addTopicList);
            $("#pricetype").css({
                display: "inline"
            });
            if(data.couponSend.priceType==20){
                $('#priceType1').prop("checked", true);
            }else if(data.couponSend.priceType==10){
                $('#priceType2').prop("checked", true);
            }else if(data.couponSend.priceType==0){
                $('#priceType0').prop("checked", true);
            }
            $("#priceTypes").css({
                display: "inline"
            });
        }else if(data.couponSend.sendCouponType ==4){
            console.log("wwwwwwwwwwwwwwwwwwwwwwwwwww")
            // if(data.couponSendCustomerList.length>0){
            //     $("#securities").css({
            //         display: "block"
            //     });
            // }else{
            //     $("#securities").css({
            //         display: "none"
            //     });
            // }
            $("#twoOrThree").css({
                display: "block"
            });
            $("#two").css({
                display: "block"
            });
            $("#time").css({
                display: "block"
            });
            $("#topic-1").css({
                display: "none"
            });
            $("#topic-2").css({
                display: "block"
            });
            $('#sendCondition').val(data.couponSend.sendCondition);
            if (data.couponSend.sendCondition == 1) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            if (data.couponSend.sendCondition == 2) {
                $("#two").css({
                    display: "block"
                });
                $("#two-1").css({
                    display: "block"
                });
                $("#two-2").css({
                    display: "block"
                });
                $("#two-3").css({
                    display: "block"
                });
                $('#sendCondition').val(data.couponSend.sendCondition);
                $('#orderAmount').val(data.couponSend.orderAmount);
                var whosus= sessionStorage.getItem("whosus")
                if (data.couponSend.applWarehouse == whosus || data.couponSend.applWarehouse == whosus) {
                    document.getElementById("wareHouse").checked = true;
                    $("input[name='wareHouse']").each(function () {
                        $(this).prop("checked", true);
                    });
                } else {
                    var groupCheckbox = data.couponSend.applWarehouse.split(",");
                    for (var i = 0; i < groupCheckbox.length; i++) {
                        var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
                        var ss=""
                        $.each(warehouses.data,function(k,s){
                            if(groupCheckbox[i]==s.warehouseCode){
                                $('#wareHouse'+s.warehouseCode+'').prop("checked", true);
                            }
                        })
                        /*if (groupCheckbox[i] == '1') {
                            $('#wareHouse1').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '2') {
                            $('#wareHouse2').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '4') {
                            $('#wareHouse3').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '5') {
                            $('#wareHouse4').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '9') {
                            $('#wareHouse5').prop("checked", true);
                        }
                        if (groupCheckbox[i] == '10') {
                            $('#wareHouse6').prop("checked", true);
                        }*/
                    }
                }
                var groupCheckbox = data.couponSend.applPaidType.split(",");
                for (var i = 0; i < groupCheckbox.length; i++) {
                    if (groupCheckbox[i] == '1001') {
                        $('#payType1').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1301') {
                        $('#payType2').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1401') {
                        $('#payType3').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1101') {
                        $('#payType4').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '1201') {
                        $('#payType5').prop("checked", true);
                    }
                }
            }
            if (data.couponSend.sendCondition == 3) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            if (data.couponSend.sendCondition == 4) {
                $("#two-1").css({
                    display: "none"
                });
                $("#two-2").css({
                    display: "none"
                });

                $("#two-3").css({
                    display: "none"
                });
            }
            $("#customerTypef1").css({
                display: "none"
            });
            $("#customerTypef2").css({
                display: "none"
            });
            $("#customerTypef0").css({
                display: "none"
            });
            if (data.couponSend.customerType == '40') {
                document.getElementById("customerType").checked = true;
                $("input[name='customerType']").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                var groupCheckbox = data.couponSend.customerType.split(",");
                for (var i = 0; i < groupCheckbox.length; i++) {
                    if (groupCheckbox[i] == '11') {
                        $('#customerType1').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '12') {
                        $('#customerType2').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '20') {
                        $('#customerType3').prop("checked", true);
                    }
                    if (groupCheckbox[i] == '30') {
                        $('#customerType4').prop("checked", true);
                    }

                }
            }
            $('#logmin').val(data.couponSend.startTime);
            if (b.endTime != null && b.endTime != '') {
                $('#logmax').val(b.endTime);
            } else {
                $('#logmax').css({
                    display: "none"
                });
                $("#word").css({
                    display: "block"
                });
            }
            addList.push(data.couponSendCustomerList);
            addTopicList.push(data.couponSendTopicList);
            cust_list(addList);
            coupon_list_2(addTopicList);
            $("#pricetype").css({
                display: "none"
            });
        }
        if (data.couponSend.auditStatus == 10) {
            $('#checkInfo').hide();
        }
        else {
            auditlist(data);
            document.getElementById('datatable3_info').classList.add('hide');
        }
    },
    error: function () {
        $.Huimodalalert('失败！', 1000);
    }
});

function cust_list(data) {
    dataSource1.splice(0, dataSource1.length);//清空数组
    console.log(data)
    $.each(data, function (k, v) {
        $.each(v, function (i, field) {
            var rowData = new Array();
            rowData.push(field.memberId);
            rowData.push(field.custType);
            rowData.push(field.custName);
            rowData.push(field.custArea);
            dataSource1.push(rowData);
        });
    });
    initDataTable(dataSource1);

    function initDataTable(dataSource1) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable

        $("#datatable").DataTable({
            "bSort": false,//禁止排序
            "autoWidth": false,
            "ordering": true,
            "searching": false,
            "paging": true,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu": [10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据"
            },
            data: dataSource1,
            columnDefs: [
                // {"data":null, "targets":0 },
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if (row[1] == 20) {
                            val = '普通客户';
                            return val;
                        }
                        else if (row[1] == 30) {
                            val = '认证客户';
                            return val;
                        }
                        else if (row[1] == 12) {
                            val = '签约客户(分销)';
                            return val;
                        }
                        else if (row[1] == 11) {
                            val = '签约客户(非分销)';
                            return val;
                        }
                    },
                    "targets": 1
                },

            ]
        });
    };
}

function coupon_list(data) {
    console.log(data);
    dataSource2.splice(0, dataSource2.length);//清空数组
    $.each(data, function (k, v) {
        $.each(v, function (i, field) {
            var rowData = new Array();
            /* var statu=''
             if(data.couponSendTopics.topicStatus)*/
            rowData.push(field.topicCode);
            rowData.push(field.topicName);
            rowData.push(field.amount);
            rowData.push(field.useBegtime);
            rowData.push(field.topicStatus); //10已生效，20已失效
            rowData.push(field.issuedNum);
            rowData.push(field.sendNum);
            rowData.push(field.useEndtime);
            rowData.push(field.topicId);
            rowData.push(field.sendTopicId);
            rowData.push(field.dayNumber);
            rowData.push(field.topicType);
            dataSource2.push(rowData);
        });
    });
    initDataTable(dataSource2);
    function initDataTable(dataSource2) {
        var dttable = $('#datatable1').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable1").DataTable({
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": true,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu": [10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据"
            },
            data: dataSource2,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if (row[11] == 10) {
                            val = '满减券';
                        } else {
                            val = '运费券';
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0];
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1];
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2];
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        if (row[10] == 0) {
                            var val = '<span>' + row[3] + '</span><br>~<br><span>' + row[7] + '</span>';
                            return val;
                        }
                        else {
                            var val = '<span>领到券当日开始' + row[10] + '天内有效</span>';
                            return val;
                        }
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '已生效';
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[5];
                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '<input type="text" name="' + row[9] + '" id="' + row[8] + '" onkeyup="this.value=this.value.replace(/\\D/g,\'\');" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')" value="' + row[6] + '" readonly style="width:50px;text-align: center;border: 1px solid #333">';
                        return val;
                    },
                    "targets": 7
                },

            ]
        });
    };
}

function coupon_list_2(data) {
    dataSource2.splice(0, dataSource2.length);//清空数组
    $.each(data, function (k, v) {
        console.log(data);
        $.each(v, function (i, field) {
            var rowData = new Array();
            /* var statu=''
             if(data.couponSendTopics.topicStatus)*/
            rowData.push(field.topicCode);
            rowData.push(field.topicName);
            rowData.push(field.amount);
            rowData.push(field.useBegtime);
            rowData.push(field.topicStatus); //10已生效，20已失效
            rowData.push(field.issuedNum);
            rowData.push(field.sendNum);
            rowData.push(field.useEndtime);
            rowData.push(field.topicId);
            rowData.push(field.sendTopicId);
            rowData.push(field.dayNumber);
            rowData.push(field.sendTotalNum);
            rowData.push(field.topicType);
            dataSource2.push(rowData);
        });
    });
    initDataTable(dataSource2);

    function initDataTable(dataSource2) {
        var dttable = $('#datatable2').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable2").DataTable({
            "autoWidth": true,
            "ordering": true,
            "searching": false,
            "paging": true,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu": [10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据"
            },
            data: dataSource2,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if (row[12] == 10) {
                            val = '满减券';
                        } else {
                            val = '运费券';
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0];
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1];
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2];
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        if (row[10] == 0) {
                            var val = '<span>' + row[3] + '</span><br>~<br><span>' + row[7] + '</span>';
                            return val;
                        }
                        else {
                            var val = '<span>领到券当日开始' + row[10] + '天内有效</span>';
                            return val;
                        }
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[5];
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = 1;
                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '<input type="text" name="' + row[11] + '" id="' + row[8] + '" onkeyup="this.value=this.value.replace(/\\D/g,\'\');" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')" value="' + row[11] + '" style="width:50px;text-align: center;border: 1px solid #333" readonly="readonly">';
                        return val;
                    },
                    "targets": 7
                },
                /*{
                    "render": function (data, type, row, meta) {
                        var val = '<a><span class="list" onclick="topicDelete2(this)" id="' + row[9] + '">删除</span></a>';
                        return val;
                    },

                    "targets": 8
                }*/
            ]
        });
    };
};

function auditlist(data) {
    dataSource3.splice(0, dataSource3.length);//清空数组
    var rowData = new Array();
    rowData.push(data.couponSend.sendCouponCode);
    rowData.push(data.couponSend.auditPerson);
    rowData.push(data.couponSend.auditTime);
    rowData.push(data.couponSend.auditStatus);
    if (data.couponSend.auditStatus == 30) {
        rowData.push(data.couponSend.failExplan);
        rowData.push(data.couponSend.failReason);
    } else if (data.couponSend.auditStatus == 20) {
        rowData.push(data.couponSend.failExplan = '');
        rowData.push(data.couponSend.failReason = '');
    } else {
        rowData.push(data.couponSend.failExplan = '');
        rowData.push(data.couponSend.failReason = '');
    }
    dataSource3.push(rowData);
    initDataTable(dataSource3);

    function initDataTable(dataSource3) {
        var dttable = $('#datatable3').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable3").DataTable({
            "autoWidth": false,
            "ordering": true,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource3,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        if (row[3] == 20) {
                            var val = '<span>审核通过</span>';
                            return val;
                        }else if (row[3] == 50) {
                            var val = '<span>审核通过</span>';
                            return val;
                        }else if (row[3] == 60) {
                            var val = '<span>审核通过</span>';
                            return val;
                        }
                        else if (row[3] == 30) {
                            var val = '<span>审核不通过</span>';
                            return val;
                        }
                        else if (row[3] == 70) {
                            var val = '<span>强制失效</span>';
                            return val;
                        }
                        else {
                            var val = '';
                            return val;
                        }
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        if (row[5] != '' && row[4] != '') {
                            var val = '' + row[5] + ':' + row[4] + '';
                            return val
                        }
                        else if (row[5] != '' || row[4] != '') {
                            var val = '' + row[5] + '' + row[4] + '';
                            return val
                        }
                        else {
                            var val = '';
                            return val
                        }
                    },
                    "targets": 4
                }
            ]
        });
    };
}

$('#submitCheck').click(function () {
    if ($("input[type='radio'][value='审核通过']").is(':checked')) {
        $.ajax({
            url: root.couponInter.coupon_oneAuditPass,
            cache: false,  //禁用缓存
            type: "POST",
            dataType: 'json',
            // contentType: "application/json",
            data: {
                "sendCouponId": a,
                "auditPersonName": user
            },
            success: function (data) {
                console.log(aaaaaa);
                $.Huimodalalert(data.message, 1000);
            },
            error: function () {
                $.Huimodalalert('失败！', 1000);
            }
        })
    }
    else if ($("input[type='radio'][value='审核不通过']").is(':checked')) {
        var failReason = $('#failReason').val();
        var failExplan = $('#failExplan').val();
        $.ajax({
            url: root.couponInter.coupon_oneAuditNotPass,
            cache: false,  //禁用缓存
            type: "POST",
            dataType: 'json',
            // contentType: "application/json",
            data: {
                "sendCouponId": a,
                "auditPersonName": user,
                "failReason": failReason,
                "failExplan": failExplan
            },
            success: function (data) {
            },
            error: function () {
                $.Huimodalalert('失败！', 1000);
            }
        })
    }
})
$('#putout').attr("href", root.couponInter.coupon_exportUserExcel + a);

function sendDutyDept(Val) {
    switch (parseInt(Val)) {
        case 1:
            return '商品问题';
            break;
        case 2:
            return '仓储/物流问题';
            break;
        case 3:
            return '财务问题';
            break;
        case 4:
            return '网站运营问题';
            break;
        case 5:
            return '服务体验问题';
            break;
        case 6:
            return '运费问题';
            break;
        case 7:
            return '技术问题';
            break;
    }
}